var soid = getUrlParam("soid");
var type = getUrlParam("type");
document.getElementsByClassName("mui-title")[0].innerHTML = type;
var data;
var list = document.getElementById('cardContainer');
var page = 1;
var flag = false;
var address=null,minp=null,maxp=null,minv=null,maxv=null;
mui.init({
  pullRefresh: {
    container: '#pullrefresh',
    down: {
      callback: function() {
        list.innerHTML = list.innerHTML = "";
        page = 1;
        getData();
        this.endPulldownToRefresh();
      }
    },
    up: {
      contentrefresh: '正在加载...',
      auto:true,
      callback: function() {
          console.log(page);
        getData(page,address,minp,maxp,minv,maxv);
        page++;
        this.endPullupToRefresh(flag);
      }
    }
  }
});
var cardData = {};


$(".fui-downmenu-item").click(function(){
  var self = $(this);
  var input = self.attr("data-input");
  $(".fui-downmenu-item[data-input='"+input+"']").removeClass("fui-downmenu-active");
  self.addClass("fui-downmenu-active");
  $("[data-menu-frist]").removeClass("fui-downmenu-active");
  $("input[name='"+input+"']").val(self.attr("data-value"));
  $(".fui-layer").css("display","none");

  address = $("input[name='address']").val();
  var people = $("input[name='people']").val();
  var price = $("input[name='price']").val();
  if(people==""){
    minp=null;
    maxp=null;
  }else{
    var temp = people.split("-");
    minp=temp[0];
    maxp=temp[1];
  }

  if(price==""){
    minv=null;
    maxv=null;
  }else{
    var temp = price.split("-");
    minv=temp[0];
    maxv=temp[1];
  }


  console.log(address+"..."+people+"..."+price+"..."+minp+"..."+maxp+"..."+page);
  page = 1;
  getData(page,address,minp,maxp,minv,maxv);
  page++;

});
function getData(page,city,minp,maxp,minv,maxv) {
 var url = "";
 var cityUrl = "";
 var pUrl = "";
 var vUrl = "";
 if(city!=null){
   cityUrl = "&city="+city;
 }

 if(minv!=null){
   vUrl = "&startValue="+minv+"&endValue="+maxv;
 }

 if(minp!=null){
   pUrl = "&startApply="+minp+"&endApply="+maxp;
 }

	url = '/site/getLikeSite?soid='+soid+'&page='+page+'&size=10'+cityUrl+pUrl+vUrl;
  mui.ajax(url, {
    type: 'get',
    async: false,
    error:function(){
        mui.toast("没有记录");
				if(page==1){
					list.innerHTML = "";
				}
    },
    success: function(res) {
      if(res.result.length<0){
        flag = true;
      }
      cardData.list = new Array();
      for (var i = 0; i < res.result.length; i++) {
        var temp = {};
        temp.id = res.result[i].siid;
        temp.title = res.result[i].title;
        temp.price = res.result[i].price;
        temp.img = res.result[i].imgs[0].imgUrl;
        temp.label = res.result[i].tags.split("|");
        cardData.list.push(temp);
      }

      var cardTpl = template('cardTpl', cardData);
			// console.log(searchFlag);
      if(page==1){
        list.innerHTML = "";
        //mui('.mui-scroll-wrapper').scroll().scrollTo(0,0,100);
      }
      list.innerHTML = list.innerHTML + cardTpl;
    },
  });

}
